//
//  BookDetailTableViewCell.m
//  Learn
//
//  Created by zyl on 2024/4/3.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "BookDetailTableViewCell.h"

@implementation BookDetailTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    [self.contentView addSubview:self.backView];
    [self.backView addSubview:self.titleLabel];
    [self.backView addSubview:self.subTitleLabel];
    [self.backView addSubview:self.arrowImg];
    [self.backView addSubview:self.coverImg];
    
    self.contentView.backgroundColor = lClearColor;
    self.backgroundColor = lClearColor;
    return self;
}
- (UIView *)backView
{
    if (!_backView) {
        _backView = [[UIView alloc] initWithFrame:CGRectMake( 10, 0, lScreenWidth - 20, 114)];
        _backView.backgroundColor = lWhiteColor;
        [_backView addSubview:separateLineWithColor(CGRectMake(10, 113.5, lScreenWidth - 30, 0.5), rgba(229, 229, 229, 1))];
    }
    return _backView;
}
- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.frame = CGRectMake(90,20,lScreenWidth - 20 - 95 - 47,22);
        _titleLabel.font = MFontWithSize(16);
        _titleLabel.textColor = rgba(51, 51, 51, 1);
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.text = @"惠州初中英语";
    
    }
    return _titleLabel;
}
- (UILabel *)subTitleLabel
{
    if (!_subTitleLabel) {
        
        _subTitleLabel = [[UILabel alloc] init];
        _subTitleLabel.frame = CGRectMake(90,10 + 22 + 10,lScreenWidth - 20 - 95 - 47,20);
        _subTitleLabel.font = RFontWithSize(14);
        _subTitleLabel.textColor = rgba(142, 142, 142, 1);
        _subTitleLabel.textAlignment = NSTextAlignmentLeft;
        _subTitleLabel.text = @"惠州初中英语";
    
    }
    return _subTitleLabel;
}
- (UIImageView *)arrowImg
{
    if (!_arrowImg) {
        _arrowImg = [[UIImageView alloc] initWithFrame:CGRectMake(lScreenWidth - 20 - 18, 25, 8, 14)];
        _arrowImg.image = IMAGENAMED(@"ic_mine_arrow_black");
    }
    return _arrowImg;
}
- (UIImageView *)coverImg
{
    if (!_coverImg) {
        _coverImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, 15, 70, 84)];
        [_coverImg setAllCornersWithCornerRadius:15];
    }
    return _coverImg;
}
- (void)setData:(NSDictionary *)data
{
    self.titleLabel.text = data[@"productName"];
    self.subTitleLabel.text = [NSString stringWithFormat:@"适用于：%@",data[@"periodName"]];
    [self.coverImg sd_setImageWithURL:[NSURL URLWithString:data[@"cover_full"]]];
    double titleHeight = [MethodTool getTextHeightWithStr:self.titleLabel.text font:self.titleLabel.font ViewWidth:self.titleLabel.width];
    titleHeight = titleHeight > 22? titleHeight:22;
    self.titleLabel.height = titleHeight;
    self.subTitleLabel.y = self.titleLabel.bottom + 10;
    [self.backView setCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadius:0];
    if (self.isLast) {
       
        [self.backView setCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadius:15];
    }
}
@end
